package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.Menu;
import com.bjsxt.pojo.PageA;
import com.bjsxt.pojo.TreeA;
import com.bjsxt.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    //查询指定用户的菜单
    @RequestMapping("/findMoreMenu")
    public List<TreeA>  findMoreMenu(@RequestParam(defaultValue = "0") Integer id, HttpSession session){
        //获得session中的用户对象
        Admin admin = (Admin) session.getAttribute("admin");
        return  menuService.findMore(admin.getAid(), id);
    }
    //查询菜单信息响应到数据网格中
    @RequestMapping("/findAllMenu")
    public PageA<Menu> findAllMenu(Integer page,Integer rows){
      return   menuService.findMore2(page, rows);
    }
   //查询菜单与用户的权限无关
    @RequestMapping("/findMoreMenu3")
    public List<TreeA> findMoreMenu3(@RequestParam(defaultValue = "0") Integer id){
         return menuService.findMore3(id);
    }

    //添加菜单信息
    @RequestMapping("/saveMenu")
    public Integer saveMenu(Menu menu){
        return menuService.saveMenu(menu);
    }

    //修改菜单的信息
    @RequestMapping("/updateMenu")
    public Integer updateMenu(Menu menu){
        return  menuService.updateMenu(menu);
    }

   //删除菜单的信息
    @RequestMapping("/deleteMenu")
    public Integer deleteMenu(Integer mid){
        System.out.println(mid);
       return menuService.detele(mid);
    }
    //查询同步树的菜单信息
    @RequestMapping("/findMoreMenu4")
    public List<TreeA> findMoreMenu4(){
      return   menuService.findMore4();
    }
}
